function* gen() {
  while(true) {
    try {
      yield 42
    } catch (e) {
      console.log('error caught!')
    }
  }
}

let g = gen()
g.next()
g.throw( new Error('went wrong'))